/*
 * CCreateLinkAction.java
 *
 * Created on January 11, 2007, 8:21 PM
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.actions;

import org.fpdev.core.basenet.BLink;
import org.fpdev.apps.rtemaster.RouteMaster;

/**
 *
 * @author demory
 */
public class CreateLinkAction implements ACAction {

  private BLink link_;
  private boolean updateDB_;

  /** Creates a new instance of CCreateLinkAction */
  public CreateLinkAction(BLink link, boolean updateDB) {
    link_ = link;
    updateDB_ = updateDB;
  }

  public String getName() {
    return "Create Link";
  }

  public BLink getLink() {
    return link_;
  }

  public boolean doAction(RouteMaster ac) {

    ac.getEngine().getBaseNet().addLink(link_);

    if (updateDB_) {
      ac.getEngine().getDataPackage().getSpatialDataConn().createLink(link_);
      //updateDB(av.getEngine().getDB());
    }
    return true;
  }

  public boolean undoAction(RouteMaster ac) {
    DeleteLinkAction dla = new DeleteLinkAction(link_, true);
    return dla.doAction(ac);
  }
}
